import { useEffect } from "react";
import {
  Switch,
  BrowserRouter as Router,
  Route,
  Redirect,
} from "react-router-dom";

//组件
import Home from "./pages/Home";
import Icons from "./pages/Icons";
import CityList from "./pages/CityList";
import Map from "./pages/Map";
import Detail from "./pages/Detail";
import Login from "./pages/Login";
import Register from "./pages/Register";
import Collected from "./pages/Collected";
import Personal from "./pages/Personal";
import Records from "./pages/Records";
import Manage from "./pages/Manage";
import Publish from "./pages/Publish";
import Search from "./pages/Search";

import { getCurrentCity } from "./utils";

function App() {
  useEffect(() => {
    async function getLocation() {
      await getCurrentCity();
    }
    getLocation();
  }, []);

  return (
    <Router>
      <div className="App">
        <Switch>
          <Route path="/home" component={Home}></Route>
          <Route path="/icons" component={Icons}></Route>
          <Route path="/cityList" component={CityList}></Route>
          <Route path="/map" component={Map}></Route>
          <Route path="/detail" component={Detail}></Route>
          <Route path="/login" component={Login}></Route>
          <Route path="/register" component={Register}></Route>
          <Route path="/collected" component={Collected}></Route>
          <Route path="/personal" component={Personal}></Route>
          <Route path="/records" component={Records}></Route>
          <Route path="/manage" component={Manage}></Route>
          <Route path="/publish" component={Publish}></Route>
          <Route path="/search" component={Search}></Route>
          <Redirect to="/home"></Redirect>
        </Switch>
      </div>
    </Router>
  );
}

export default App;
